<template>
	<view >
		<up-image :src="imageType === 'h' ? '/static/comm/icon_yy.png' :'/static/comm/icon_yy_b.png'" width="26" height="26" bgColor="#f1f6ff00" @click="show = true;"></up-image>
		<up-action-sheet 
			:actions="locales" 
			:show="show" 
			@select="onLocaleChange"
			round="10"
		></up-action-sheet>
		<!-- 温馨提示 -->
		<up-modal :show="openShow" :showConfirmButton = "false">
			<view class="slot-content">
				<view class="close_warp" @click="openShow=false;">
					<up-image src="/static/comm/close.png" width="20" height="20" bgColor="#f1f6ff00"></up-image>
				</view>
				<view class="content_">
					<view class="content_1">{{$t('common.warm.reminder')}}</view>
					<view class="content_2">{{$t('index.language-change-confirm')}}</view>
				</view>
				<view class="but_">
					<view class="but_copy" @click="checkLanguage">{{$t('common.confirm')}}</view>
					<view class="but_close" @click="openShow=false;">{{$t('common.cancel')}}</view>
				</view>
			</view>
		</up-modal>
	</view>
</template>

<script>
	export default {
		name:"language",
		props: {
			imageType:{
				type: String,
				default: 'b'
			},
		},
		computed:{
		    locales() {
		        return [{
					    name: this.$t('locale.en'),
					    code: 'en'
					},
					// {
					//     name: this.$t('locale.zh-hans'),
					//     code: 'zh-Hans'
					// },
					{
					    name: this.$t('locale.zh-hant'),
					    code: 'zh-Hant'
					},
				]
		    }
		},
		data() {
			return {
				systemLocale: '',
				applicationLocale: '',
				show:false,
				openShow:false,
				changeLocale:{},// 切换的语言
			};
		},
		onShow() {
		  let systemInfo = uni.getSystemInfoSync();
		  this.systemLocale = systemInfo.language;
		  this.applicationLocale = uni.getLocale();
		  uni.onLocaleChange((e) => {
		    this.applicationLocale = e.locale;
		  })
		},
		methods: {
			onLocaleChange(e) {
				console.log("onLocaleChange",e);
				let systemInfo = uni.getSystemInfoSync();
				if (systemInfo.platform.toLowerCase() === 'android') {
					// uni.showModal({
					// 	content: this.$t('index.language-change-confirm'),
					// 	success: (res) => {
					// 	  if (res.confirm) {
					// 		uni.setLocale(e.code);
					// 	  }
					// 	}
					// })
					this.changeLocale = e;
					this.openShow = true;
				} else {
					uni.setLocale(e.code);
					this.$i18n.locale = e.code;
				}
				
				this.show = false;
			},
			checkLanguage(){
				const changeLocale = this.changeLocale;
				uni.setLocale(changeLocale.code);
				this.openShow=false;
			}
		}
	}
</script>

<style lang="scss">
	.container{
		color: #FFFFFF;
	}
</style>